package contact.importEmailContact;

import java.util.Scanner;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.LinkedInApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class LinkedIn {
	private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=";
	private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:";
	private static final String fieldselector = "(id,first-name,last-name,headline,location,industry,distance,current-status,current-status-timestamp,current-share,educations,three-current-positions,three-past-positions,recommendations-received,phone-numbers,im-accounts,twitter-accounts,date-of-birth,main-address,member-url-resources,picture-url,site-standard-profile-request,api-standard-profile-request,public-profile-url)";

	public static void main(String[] args) {
		OAuthService service = new ServiceBuilder()
				.provider(LinkedInApi.class)
				.apiKey("4I85XgRP1rDXhb7-52tQmN2RmO0e-3YCdba7RDs8X-kAC6V7CUzQzpiLy4hBNUD7")
				.apiSecret(
						"HrjYSm0EcPs1wI3ndZkUczR1AZIHZHr8ZJqitxKlEYOEqNKpskAejL4KHVRUgg2e")
				.build();

		Token requestToken = service.getRequestToken();

		System.out.println(AUTHORIZE_URL + requestToken.getToken());
		System.out.print(">>");
		Scanner in = new Scanner(System.in);
		Verifier verifier = new Verifier(in.nextLine());

		Token accessToken = service.getAccessToken(requestToken, verifier);

		String trueUrl = PROTECTED_RESOURCE_URL + fieldselector;
		OAuthRequest request = new OAuthRequest(Verb.GET, trueUrl);
		service.signRequest(accessToken, request);
		Response response = request.send();
		System.out.println(response.getBody());

	}

}
